<?php
// users (id, name, gender, age)
// insert into users(name, gender, age) values("zhangsan", 1, 30);
$dsn = 'mysql:host=localhost;dbname=phpcode20;charset=utf8';
$pdo = new PDO($dsn, 'root', '123456');
// query() 查询    exec() 新增 删除 修改
$name = '王五';
$mobile = '15933335555';
$money = 0;
//$sql = 'insert into users(name, mobile, money)
//        values("' . $name . '", "' . $mobile . '", ' . $money . ')';
$sql = 'insert into users(name) values ("' . $name . '")';

$result = $pdo->exec($sql); // 影响的行数
var_dump($result);
if($result > 0) {
    echo '添加成功';
} else {
    echo '添加失败';
}

